package com.orangelife.mobile.widget;
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.curry.orangelife.mobile.R;
import com.orangelife.mobile.individual.adapter.PaidStatusListViewAdapter;
import com.orangelife.mobile.shop.biz.Trader;
/**
 * 订单支付方式弹出框
 * @author Administrator
 *
 */
public class OrderPaidMethodPopupWindow extends PopupWindow {
	private List<String> data;
	private Context context;
	private TextView tvUnPaid,tvPaided,tvPaidPublish;
	private OnClickListener clicker;
	private ListView listView;
	public static String[] arrTitle;
	private int position;
	private PaidStatusListViewAdapter paidStatusListViewAdapter;
	public OnPopupWindowItemClickListener listener;
    public OrderPaidMethodPopupWindow(Context context,OnClickListener clicker){
    	this.context = context;
    	this.clicker = clicker;
    	initData();
    	initView();
    }
    
    public void setPosition(int position){
    	Trader.getInstance().setSpTyprPosition(position);
    	paidStatusListViewAdapter.notifyDataSetChanged();
    }
    /**
	 * 商家搜索条件
	 * 
	 */
	private void getShopInforCondition() {
		String s[] = context.getResources().getStringArray(
				R.array.paid_type);
		for (int i = 0; i < s.length; i++) {
			data.add(s[i]);
		}
	}
	

	private void initView() {
       View contentView = LayoutInflater.from(context).inflate(
    		   R.layout.popwin_paid_method,null);
       setContentView(contentView);
       listView = (ListView) contentView.findViewById(R.id.lvCondition);
       /* 设置popupwindow的基本属性 */
	   this.setBackgroundDrawable(new ColorDrawable(R.color.white));
	   this.setWidth(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
	   this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
	   /* 设置捕获popupwindow外的点击焦点 */
	   this.setOutsideTouchable(true);
	   setAdapter();
	}
	
	/**
	 * 设置数据
	 */
	private void initData() {
		arrTitle = context.getResources().getStringArray(
				R.array.shopInfor_title);
		data = new ArrayList<String>();
		getShopInforCondition();
	}
	/**
	 * 载入列表item
	 */
	private void setAdapter() {
		paidStatusListViewAdapter = new PaidStatusListViewAdapter(context, data);
		listView.setAdapter(paidStatusListViewAdapter);
	}
	
	/**
	 * 设置popupwindow的适配器
	 */
	public void setOnPopupWindowClickListener(
			OnPopupWindowItemClickListener listener) {
		this.listener = listener;
		paidStatusListViewAdapter.setListener(listener);
	}
	/**
	 * 为列表的item添加监听
	 */
	public interface OnPopupWindowItemClickListener {
		void onPopupWindowItemClick(int clickPositon, String strItemData);
	}
}
